package com.hlw.hr_man.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
   /**
    * 登录的servlet
    * @author Administrator
    *
    */
import javax.servlet.http.HttpSession;

import com.hlw.hr_man.Model.EmployeeModel;
import com.hlw.hr_man.Model.DeptModel;
import com.hlw.hr_man.service.EmployeeSrevice;
import com.hlw.hr_man.service.FindDeptService;
import com.hlw.hr_man.serviceImpl.EmployeeServiceImpl;
import com.hlw.hr_man.serviceImpl.FindDeptServiceImpl;
public class Logincontroller extends HttpServlet {
	EmployeeSrevice employeeservice=new EmployeeServiceImpl();
	FindDeptService  findDeptService = new FindDeptServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    	doPost(req, resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    	HttpSession session=req.getSession();
    	resp.setCharacterEncoding("utf8");
    	PrintWriter pw=resp.getWriter();
      String enumber=req.getParameter("enumber");
      String epwd=req.getParameter("epassword");
      EmployeeModel employee=employeeservice.findEmpByEnumAndEpwd(enumber, epwd);
      int eid=employee.getE_id();
      
      if(eid!=0){
    	  session.setAttribute("employeeid", eid);
    	  session.setAttribute("loginEmployee", employee);
    	  
      }
      else{
    	  eid = 0;
   
      }
      pw.write(String.valueOf(eid));
    }
}
